package com.huawei.appmarket.support.video;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.SurfaceTexture;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.TextureView.SurfaceTextureListener;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.huawei.hms.support.api.entity.core.JosStatusCodes;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.util.Locale;
import o.abd;
import o.abu;
import o.aim;
import o.akt.a;
import o.alh;
import o.aln;
import o.alo;
import o.alw;
import o.alx;
import o.alz;
import o.anr;
import o.aoc;
import o.ccz;
import o.dgm;
import o.dky.o;
import o.Logger;
import o.erq;
import o.evd;
import o.evi;
import o.evm;
import o.evn;
import o.evo;
import o.evp;
import o.evq;
import o.evr;
import o.evt;
import o.evv;
import o.evw;
import o.evz;

public class VideoPlayer extends FrameLayout implements evn, SurfaceTextureListener {
    private evz ʻ;
    private c ʻॱ;
    private abu ʼ;
    private long ʼॱ;
    private Context ʽ;
    private evw ʽॱ;
    private boolean ʾ;
    private int ʿ;
    private boolean ˈ;
    private int ˉ;
    com.google.android.exoplayer2.Player.d ˊ;
    private Drawable ˊˊ;
    private int ˊˋ;
    private String ˊॱ;
    private int ˊᐝ;
    int ˋ;
    private int ˋˊ;
    private long ˋˋ;
    private SurfaceTexture ˋॱ;
    private boolean ˋᐝ;
    private String ˌ;
    private String ˍ;
    private int ˎ;
    private boolean ˎˎ;
    private int ˎˏ;
    private int ˏ;
    private b ˏˎ;
    private final int ˏˏ;
    private evq ˏॱ;
    private evp ˑ;
    private Surface ͺ;
    private OnAudioFocusChangeListener ͺॱ;
    aoc ॱ;
    private e ॱʻ;
    private String ॱˊ;
    private boolean ॱˋ;
    private long ॱˎ;
    private d ॱͺ;
    private AudioManager ॱॱ;
    private String ॱᐝ;
    private FrameLayout ᐝ;
    private long ᐝॱ;

    public interface e {
        void ˋ(Context context, String str, int i);
    }

    public interface d {
        void ˋ(Context context);

        void ˏ(Context context);
    }

    class b extends evv {
        final /* synthetic */ VideoPlayer ˊ;
        private int ˋ = -1;

        public b(VideoPlayer videoPlayer, Context context, int i) {
            this.ˊ = videoPlayer;
            super(context, i);
        }

        public boolean ˎ() {
            if (this.ˊ.ʼॱ()) {
                return false;
            }
            return evt.ˋ(this.ˊ.getContext());
        }

        public void ˎ(int i) {
            if (i != -1) {
                if (i > 75 && i <= 105) {
                    this.ˋ = 90;
                } else if (i > 255 && i <= 285) {
                    this.ˋ = 270;
                } else if (i > 345 || i <= 15) {
                    this.ˋ = 0;
                }
                if (this.ˋ == this.ˊ.ˎˏ && this.ˊ.getContext() != null && !this.ˊ.ˌ()) {
                    this.ˊ.ॱͺ();
                    ((Activity) this.ˊ.getContext()).setRequestedOrientation(-1);
                }
            }
        }
    }

    class c extends evv {
        private int ˊ = 0;
        final /* synthetic */ VideoPlayer ˎ;

        public c(VideoPlayer videoPlayer, Context context, int i) {
            this.ˎ = videoPlayer;
            super(context, i);
        }

        public boolean ˎ() {
            return evt.ˋ(this.ˎ.getContext());
        }

        public void ˎ(int i) {
            if (i > 75 && i <= 105) {
                this.ˊ = this.ˎ.ˊˋ + 270;
            } else if (i > 255 && i <= 285) {
                this.ˊ = this.ˎ.ˊˋ + 90;
            } else if (i > 345 || i <= 15) {
                this.ˊ = this.ˎ.ˊˋ;
            }
            if (i != -1) {
                if (this.ˊ >= 360) {
                    this.ˊ -= 360;
                }
                if (this.ˎ.ˊᐝ != this.ˊ) {
                    this.ˎ.ˊᐝ = this.ˊ;
                    if (this.ˎ.ʻ != null) {
                        this.ˎ.ʻ.setRotation((float) this.ˎ.ˊᐝ);
                    }
                    this.ˎ.ˏॱ.setControllerRotation((float) this.ˎ.ˊᐝ);
                }
            }
        }
    }

    public VideoPlayer(Context context) {
        this(context, null);
    }

    public VideoPlayer(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.ˏ = 0;
        this.ˎ = 10;
        this.ॱᐝ = "posturl";
        this.ॱˋ = true;
        this.ʾ = false;
        this.ˈ = false;
        this.ʿ = -1;
        this.ˊᐝ = -1;
        this.ˊˋ = -1;
        this.ˋˊ = -1;
        this.ˉ = ccz.ॱ();
        this.ˋᐝ = false;
        this.ˎˎ = false;
        this.ˋˋ = 0;
        this.ˏˏ = 1000;
        this.ͺॱ = new 1(this);
        this.ˎˏ = -1;
        this.ॱ = new 5(this);
        this.ˊ = new 2(this);
        this.ʽ = context;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, o.ˈˋ);
        this.ˋᐝ = obtainStyledAttributes.getBoolean(o.ˉˊ, false);
        obtainStyledAttributes.recycle();
        ˎˎ();
    }

    private void ˎˎ() {
        this.ᐝ = new FrameLayout(this.ʽ);
        addView(this.ᐝ, new LayoutParams(-1, -1));
        ˏˎ();
        this.ˉ = ˎ();
    }

    public void setBuoyFullScreenMethod(e eVar) {
        this.ॱʻ = eVar;
    }

    public void setBuoyNetChangeCallBack(d dVar) {
        this.ॱͺ = dVar;
    }

    public d ˏ() {
        return this.ॱͺ;
    }

    protected int ˎ() {
        if (ˌ() || !(getContext() instanceof Activity)) {
            return 4;
        }
        return dgm.ˎ((Activity) getContext());
    }

    public String ॱ() {
        return this.ॱˊ;
    }

    public String ˋ() {
        return this.ॱᐝ;
    }

    public void setController(evq o_evq) {
        this.ᐝ.removeView(this.ˏॱ);
        this.ˏॱ = o_evq;
        this.ˏॱ.ˊ();
        this.ˏॱ.setVideoPlayer(this);
        this.ᐝ.addView(this.ˏॱ, new LayoutParams(-1, -1));
    }

    private void ˏˎ() {
        this.ᐝ.removeView(this.ˏॱ);
        this.ˏॱ = new evo(this.ʽ, ˌ());
        this.ˏॱ.ˊ();
        this.ˏॱ.setVideoPlayer(this);
        this.ᐝ.addView(this.ˏॱ, new LayoutParams(-1, -1));
    }

    public ImageView ॱॱ() {
        return this.ˏॱ.ॱ();
    }

    public void ᐝ() {
        if (!TextUtils.isEmpty(this.ॱˊ)) {
            if (this.ˎˎ) {
                ॱॱ().performClick();
                return;
            }
            Logger.ˏ("VideoPlayer", "startPlay mCurrentState: " + this.ˏ);
            if (this.ˏ == 0) {
                if (this.ˎ == 10) {
                    evr.ˊ().ˏ((evn) this);
                }
                this.ˏॱ.ˏ();
                ͺॱ();
                ˏˏ();
                ॱʽ();
            }
        }
    }

    public void ʼ() {
        if (!this.ˏॱ.ʽ() && this.ˏ == 2) {
            try {
                if (this.ʼ != null) {
                    this.ʼ.ˋ(false);
                    this.ˏ = 5;
                    this.ˏॱ.ˎ(this.ˏ);
                }
            } catch (IllegalStateException e) {
                Logger.e("VideoPlayer", e.toString());
            }
        }
    }

    public void ʽ() {
        if (TextUtils.isEmpty(this.ॱˊ) || this.ˏ != 0 || this.ˎˎ) {
            Logger.ˏ("VideoPlayer", "start mCurrentState: " + this.ˏ);
            return;
        }
        this.ˏॱ.ˎ(-2);
        if (this.ˎ == 10) {
            evr.ˊ().ˏ((evn) this);
        }
        this.ˏॱ.ˏ();
        ͺॱ();
        ˏˏ();
        ॱʽ();
    }

    public void ʻ() {
        if (this.ˏ == 4 || this.ˏ == 5) {
            this.ˏ = 3;
            this.ˏॱ.ˎ(this.ˏ);
            this.ʼ.ˋ(true);
        } else if (this.ˏ == 7 || this.ˏ == -1) {
            ˏ(0);
        }
        if (this.ˋˊ != 1) {
            ˎˏ();
        }
        Logger.ˏ("VideoPlayer", "restart mediaPlayer error,mCurrentState: " + this.ˏ);
    }

    public void ॱˊ() {
        if (this.ʼ == null) {
            Logger.ˏ("VideoPlayer", "pause mediaplayer null");
        } else if (this.ˏ == 3 || this.ˏ == 6) {
            ˋॱ();
        }
    }

    public void ˊॱ() {
        ॱˊ();
        this.ˏ = 5;
    }

    public void ˋॱ() {
        this.ʼ.ˋ(false);
        this.ˏ = 4;
        this.ˏॱ.ˎ(this.ˏ);
        this.ˏॱ.ˊ(this.ॱˊ, (int) ˊᐝ());
        ˑ();
    }

    public void ॱ(long j) {
        if (this.ʼ != null) {
            this.ʼ.ˎ(j);
        }
    }

    public boolean ͺ() {
        if (this.ʼ == null || this.ˋˊ == 1) {
            return true;
        }
        try {
            this.ʼ.ॱ(0.0f);
            ˑ();
            this.ˋˊ = 1;
            return true;
        } catch (IllegalStateException e) {
            Logger.e("VideoPlayer", "mute play error");
            return false;
        }
    }

    public boolean ˏॱ() {
        if (this.ʼ == null || this.ˋˊ == 2) {
            return true;
        }
        try {
            this.ʼ.ॱ(1.0f);
            this.ˋˊ = 2;
            if (ᐝॱ()) {
                return true;
            }
            ˎˏ();
            return true;
        } catch (IllegalStateException e) {
            Logger.e("VideoPlayer", "unmute play error");
            return false;
        }
    }

    public void setLooping(boolean z) {
        if (this.ʼ != null) {
            this.ʼ.ˎ(z ? 2 : 0);
        }
    }

    public boolean ॱᐝ() {
        return this.ˏ == 0;
    }

    public boolean ॱˋ() {
        return this.ˏ == 2;
    }

    public boolean ॱˎ() {
        return this.ˏ == 6;
    }

    public boolean ʻॱ() {
        return this.ˏ == 3;
    }

    public boolean ᐝॱ() {
        return this.ˏ == 4 || this.ˏ == 5;
    }

    public boolean ʾ() {
        return this.ˏ == 5;
    }

    public boolean ʿ() {
        return this.ˏ == -1;
    }

    public boolean ˈ() {
        return this.ˏ == 7;
    }

    public boolean ʼॱ() {
        return this.ˎ == 11;
    }

    public boolean ʽॱ() {
        return this.ˎ == 10;
    }

    public long ˊˊ() {
        long j = 0;
        try {
            if (this.ʼ != null) {
                j = this.ʼ.ᐝ();
            }
        } catch (IllegalStateException e) {
            Logger.e("VideoPlayer", "getDuration error," + e.toString());
        }
        return j;
    }

    public long ˊᐝ() {
        long j = -1;
        try {
            if (this.ʼ != null) {
                j = this.ʼ.ʼ();
            }
        } catch (IllegalStateException e) {
            Logger.e("VideoPlayer", "getCurrentPosition error," + e.toString());
        }
        return j;
    }

    public int ˉ() {
        return this.ʼ != null ? this.ʼ.ˋ() : 0;
    }

    private void ˎˏ() {
        if (this.ॱॱ == null) {
            this.ॱॱ = (AudioManager) getContext().getSystemService("audio");
        }
        this.ॱॱ.requestAudioFocus(this.ͺॱ, 3, 2);
    }

    private void ˑ() {
        if (this.ॱॱ != null) {
            this.ॱॱ.abandonAudioFocus(this.ͺॱ);
        }
    }

    private void ͺॱ() {
        try {
            this.ॱˎ = SystemClock.elapsedRealtime();
            this.ʼ = abd.ॱ(this.ʽ, new DefaultTrackSelector(new a(null)));
            if (this.ˋˊ != 1) {
                this.ʼ.ॱ(0.0f);
            }
        } catch (Exception e) {
            Logger.e("VideoPlayer", "initMediaPlayer error: " + e.toString());
        }
    }

    private void ˏˏ() {
        if (this.ʻ == null) {
            this.ʻ = new evz(this.ʽ);
            this.ʻ.setSurfaceTextureListener(this);
            this.ʻ.setClickable(true);
        }
    }

    private void ॱʽ() {
        this.ᐝ.removeView(this.ʻ);
        this.ᐝ.addView(this.ʻ, 0, new LayoutParams(-1, -1, 17));
    }

    private void ॱ(Context context) {
        if (context != null) {
            if (this.ʻॱ == null) {
                this.ʻॱ = new c(this, context, 3);
            }
            this.ʻॱ.ˏ();
        }
    }

    private void ـ() {
        if (this.ʻॱ != null) {
            this.ʻॱ.ˋ();
        }
    }

    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
        if (this.ˋॱ == null) {
            this.ˋॱ = surfaceTexture;
            ˏ((long) this.ˏॱ.ˎ(this.ॱˊ));
        } else if (this.ʻ != null) {
            this.ʻ.setSurfaceTexture(this.ˋॱ);
        }
    }

    private void ˏ(long j) {
        if (!TextUtils.isEmpty(this.ॱˊ) && this.ʼ != null) {
            try {
                this.ʼ.ˏ(this.ˊ);
                this.ʼ.ˏ(this.ॱ);
                alx o_alh = new alh();
                aim ˎ = new o.aij.c(new alw(evm.ॱ().ˋ(), new aln(this.ʽ, o_alh, new evi(anr.ॱ(this.ʽ.getApplicationContext(), "huawei"), this.ʽ, ˋˋ().ॱ(), ॱ(), this.ˍ, o_alh, JosStatusCodes.RTN_CODE_COMMON_ERROR, JosStatusCodes.RTN_CODE_COMMON_ERROR, true)), new alo(), new alz(evm.ॱ().ˋ(), 20480), 3, null)).ˎ(Uri.parse(this.ॱˊ), null, null);
                if (this.ͺ == null) {
                    this.ͺ = new Surface(this.ˋॱ);
                }
                this.ʼ.ˋ(this.ͺ);
                this.ʼ.ˋ(ˎ);
                this.ˏ = 2;
                this.ˏॱ.ˎ(this.ˏ);
                if (j > 0) {
                    this.ʼ.ˎ(j);
                }
                this.ʼ.ˋ(true);
                Logger.ˏ("VideoPlayer", "openMediaPlayer mCurrentState: " + this.ˏ);
            } catch (Exception e) {
                Logger.e("VideoPlayer", "openMediaPlayer error" + e.toString());
            }
        }
    }

    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
    }

    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        return this.ˋॱ == null;
    }

    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
    }

    public void ˊˋ() {
        long currentTimeMillis = System.currentTimeMillis();
        if (Math.abs(currentTimeMillis - this.ˋˋ) >= 1000) {
            this.ˋˋ = currentTimeMillis;
            if (!TextUtils.isEmpty(ॱ())) {
                if (ˌ()) {
                    if (this.ॱʻ == null) {
                        Logger.e("VideoPlayer", "enterFullScreen error , buoyFullScreenMethod is null!");
                    } else {
                        this.ॱʻ.ˋ(this.ʽ, ॱ(), (int) ˊᐝ());
                    }
                } else if (this.ˎ != 11) {
                    Activity activity = (Activity) getContext();
                    ˋ((Context) activity);
                    if (this.ʻ != null) {
                        this.ʻ.setCenterCrop(false);
                        this.ॱˋ = false;
                        this.ʻ.setOriginalMatrix();
                    }
                    ViewGroup viewGroup = (ViewGroup) ((Activity) this.ʽ).findViewById(16908290);
                    removeView(this.ᐝ);
                    ViewGroup.LayoutParams layoutParams = new LayoutParams(-1, -1);
                    if (this.ᐝ.getParent() instanceof ViewGroup) {
                        ((ViewGroup) this.ᐝ.getParent()).removeView(this.ᐝ);
                    }
                    viewGroup.addView(this.ᐝ, layoutParams);
                    this.ᐝ.setBackgroundColor(-16777216);
                    this.ˊˋ = evt.ˋ(activity);
                    this.ˎˏ = evt.ˋ((Activity) getContext());
                    ˊ(getContext());
                    this.ˎ = 11;
                    this.ˏॱ.ˋ(this.ˎ);
                    new Handler().postDelayed(new 4(this), 30);
                }
            }
        }
    }

    public boolean ˊ() {
        if (this.ˎ != 11) {
            return false;
        }
        ـ();
        Context context = (Activity) getContext();
        ˏ(context);
        if (this.ʻ != null) {
            this.ʻ.setCenterCrop(true);
            this.ॱˋ = true;
            this.ʻ.setRotation(0.0f);
        }
        this.ˏॱ.ˋॱ();
        if (this.ʻ != null) {
            this.ʻ.ˎ();
        }
        ((ViewGroup) context.findViewById(16908290)).removeView(this.ᐝ);
        ViewGroup.LayoutParams layoutParams = new LayoutParams(-1, -1);
        if (this.ᐝ.getParent() instanceof ViewGroup) {
            ((ViewGroup) this.ᐝ.getParent()).removeView(this.ᐝ);
        }
        addView(this.ᐝ, layoutParams);
        this.ᐝ.setBackgroundColor(0);
        this.ˎ = 10;
        this.ˏॱ.ˋ(this.ˎ);
        if (ʿ()) {
            ˍ();
        }
        return true;
    }

    public void ˋˊ() {
        this.ˏ = 0;
        this.ˋˊ = -1;
        this.ˊᐝ = -1;
        this.ˊˋ = -1;
        ˑ();
        this.ॱॱ = null;
        if (this.ʼ != null) {
            new Thread(new Runnable(this) {
                final /* synthetic */ VideoPlayer ˏ;

                {
                    this.ˏ = r1;
                }

                public void run() {
                    synchronized (VideoPlayer.class) {
                        if (this.ˏ.ʼ != null) {
                            this.ˏ.ʼ.ॱ(this.ˏ.ˊ);
                            this.ˏ.ʼ.ॱ(this.ˏ.ॱ);
                            this.ˏ.ʼ.ʽ();
                            this.ˏ.ʼ = null;
                        }
                    }
                }
            }).start();
        }
        this.ᐝ.removeView(this.ʻ);
        this.ʻ = null;
        if (this.ͺ != null) {
            this.ͺ.release();
            this.ͺ = null;
        }
        if (this.ˋॱ != null) {
            this.ˋॱ.release();
            this.ˋॱ = null;
        }
    }

    public void ˍ() {
        long j = 0;
        int i = -1;
        if (ʻॱ() || ॱˎ() || ᐝॱ()) {
            j = ˊᐝ();
            i = (int) j;
        } else if (ˈ()) {
            j = ˊˊ();
            i = 0;
        }
        this.ˏॱ.ˊ(this.ॱˊ, i);
        ˋˊ();
        if (this.ˏॱ != null) {
            this.ˎ = 10;
            this.ˏॱ.ॱ(j);
            this.ˏॱ.ˋ();
        }
    }

    private void ˏ(Context context) {
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            ActionBar actionBar = activity.getActionBar();
            if (actionBar != null && this.ˈ) {
                actionBar.show();
            }
            Window window = activity.getWindow();
            window.clearFlags(WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
            window.setNavigationBarColor(this.ʿ);
            if (evd.ˎ()) {
                if (erq.ˏ(this.ʿ)) {
                    evd.ˊ(window, 1);
                } else {
                    evd.ˊ(window, 0);
                }
            }
            if (this.ˊˊ != null && VERSION.SDK_INT >= 26) {
                window.getDecorView().setBackground(this.ˊˊ);
            }
        }
    }

    public void ˋ(Context context) {
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            Window window = activity.getWindow();
            window.addFlags(WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
            ActionBar actionBar = activity.getActionBar();
            if (actionBar != null && actionBar.isShowing()) {
                this.ˈ = true;
                ˊ(actionBar);
                actionBar.hide();
            }
            this.ʿ = window.getNavigationBarColor();
            window.setNavigationBarColor(-16777216);
            evd.ˊ(window, 1);
            if (VERSION.SDK_INT >= 26) {
                this.ˊˊ = window.getDecorView().getBackground();
                window.getDecorView().setBackground(new ColorDrawable(-16777216));
            }
        }
    }

    private void ˊ(ActionBar actionBar) {
        try {
            actionBar.getClass().getDeclaredMethod("setShowHideAnimationEnabled", new Class[]{Boolean.TYPE}).invoke(actionBar, new Object[]{Boolean.valueOf(false)});
        } catch (Exception e) {
            Logger.ˋ("VideoPlayer", "setShowHideAnimationEnabled error: " + e.toString());
        }
    }

    public View ˋᐝ() {
        return this;
    }

    public void setVideoTag(int i) {
        this.ˋ = i;
    }

    protected void onDetachedFromWindow() {
        if (ʽॱ()) {
            ॱͺ();
            this.ˎˏ = -1;
        }
        super.onDetachedFromWindow();
    }

    private void ॱͺ() {
        if (this.ˏˎ != null) {
            this.ˏˎ.ˋ();
        }
        this.ˎˏ = -1;
    }

    public void ˊ(Context context) {
        if (context != null) {
            if (this.ˏˎ == null) {
                this.ˏˎ = new b(this, context, 3);
            }
            this.ˏˎ.ˏ();
        }
    }

    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (obj instanceof VideoPlayer) {
            return TextUtils.equals(this.ॱˊ, ((VideoPlayer) obj).ॱ());
        }
        return false;
    }

    public int hashCode() {
        if (TextUtils.isEmpty(this.ॱˊ)) {
            return super.hashCode();
        }
        return this.ॱˊ.toUpperCase(Locale.US).hashCode();
    }

    public evp ˋˋ() {
        return this.ˑ;
    }

    public void setVideoBaseInfo(evp o_evp) {
        this.ˑ = o_evp;
        if (this.ˑ != null) {
            this.ॱˊ = this.ˑ.ˊ();
            this.ˊॱ = this.ˑ.ॱ();
            this.ॱᐝ = this.ˑ.ˋ();
            this.ˍ = this.ˑ.ॱॱ();
            this.ˌ = this.ˑ.ʻ();
            this.ˎˎ = this.ˑ.ˏॱ();
            this.ˏॱ.ˏ(this.ˑ);
        }
    }

    public void setVideoPlayCallback(evw o_evw) {
        this.ʽॱ = o_evw;
    }

    public void setCurrentMode(int i) {
        if (i == 11) {
            this.ˎ = 11;
        } else {
            this.ˎ = 10;
        }
    }

    public boolean ˌ() {
        return this.ˋᐝ;
    }
}
